package trying.EasyRule;

import org.jeasy.rules.api.*;
import org.jeasy.rules.core.DefaultRulesEngine;
import org.junit.runner.RunWith;

public class UseEasyRule {
    public static void main(String[] args) {
        Facts facts = new Facts();
        facts.put("rain",true);
        Rules rules = new Rules();
        rules.register(new WeatherRule());
        RulesEngine rulesEngine = new DefaultRulesEngine();
        rulesEngine.fire(rules,facts);

        //一个被触发则不判断其他条件
        RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true);
        RulesEngine fizzBuzzEngine = new DefaultRulesEngine(parameters);
        // 创建规则容器并添加规则
        rules = new Rules();
        rules.register(new AllRule.FizzRule());
        rules.register(new AllRule.BuzzRule());
        rules.register(new AllRule.FizzBuzzRule(new AllRule.FizzRule(), new AllRule.BuzzRule()));
        rules.register(new AllRule.NonFizzBuzzRule());

        facts = new Facts();
        for (int i = 1; i <= 100; i++) {
            facts.put("number", i);
            fizzBuzzEngine.fire(rules, facts);
            System.out.println();
        }
    }
}
